From golang:1.17.2-alpine3.14 as builder

RUN apk add --no-cache \
  wget \
  git

RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 \
  && chmod +x /usr/local/bin/dumb-init

RUN mkdir -p /go/src/gitee.com/monitor_dev/multitude-cloud-exporter
WORKDIR /go/src/gitee.com/monitor_dev/multitude-cloud-exporter

# Cache dependencies
COPY go.mod .
COPY go.sum .

RUN export GOPROXY=https://goproxy.cn && GO111MODULE=on go mod download

# Build real binaries
COPY . .
RUN go build -ldflags " \
    -X main.versions=0.0.1 \
    -X main.branch=`git rev-parse HEAD` \
    -X main.buildData=`date -u '+%Y-%m-%d_%H:%M:%S'` \
    " -v -o packet/multitude-cloud-exporter cmd/multitude-cloud-exporter/main.go

# Executable image
FROM alpine

COPY --from=builder /go/src/gitee.com/monitor_dev/multitude-cloud-exporter/packet/multitude-cloud-exporter /multitude-cloud-exporter
COPY --from=builder /usr/local/bin/dumb-init /usr/local/bin/dumb-init

WORKDIR /

ENTRYPOINT ["/usr/local/bin/dumb-init", "/multitude-cloud-exporter"]